<template>
	<view class="columnbox wdh-100 content">
		<!-- 微信折扣 -->
		<view class="info-box wdh-100 columnbox">
			<view class="rowbox wdh-100 one-info spb">
				<view>微信折扣</view>
				<input v-model="zhekouwx" type="digit" placeholder-class="noinfo" placeholder="点击输入" />
			</view>
			<view class="nodetext">
				<rich-text :nodes="nodeTextwx" class="nodetext"></rich-text>
			</view>
			<view class="bottom-box wdh-100 rowbox">
				<view @click="handleSubmit" class="one-btn rowbox def-bgcol">保存</view>
			</view>
			<view class="weekNotice" v-if="showWeekNotice">
				<view class="">
					{{buymsg}}
				</view>
				<view class="btncont">
					<u-button v-if="!isIos" type="primary" size="mini" text="续费" @click="handleShowAndrRenw"></u-button>
					<u-button v-if="isIos" type="primary" size="mini" text="联系客服" @click="handleKefu"></u-button>
				</view>
			</view>
			<IosKefu :show="showIosKefu" :type="matype" @close="closeIosKefu"></IosKefu>
			<AndrTaocan :show="showAndrTaocan" :taocanid="7" @close="closeAndrTaocan" @refsh="handlerefsh"></AndrTaocan>
		</view>
		<!-- 余额折扣 -->
		<view class="info-box wdh-100 columnbox">
			<view class="rowbox wdh-100 one-info spb">
				<view>余额支付折扣</view>
				<input v-model="zhekouye" type="digit" placeholder-class="noinfo" placeholder="点击输入" />
			</view>
			<rich-text :nodes="nodeTextye" class="nodetext"></rich-text>

			<view class="bottom-box wdh-100 rowbox">
				<view @click="handleSubmit" class="one-btn rowbox def-bgcol">保存</view>
			</view>
			<view class="weekNotice" v-if="showWeekNotice">
				<view class="">
					{{buymsg}}
				</view>
				<view class="btncont">
					<u-button v-if="!isIos" type="primary" size="mini" text="续费" @click="handleShowAndrRenw"></u-button>
					<u-button v-if="isIos" type="primary" size="mini" text="联系客服" @click="handleKefu"></u-button>
				</view>
			</view>
			<IosKefu :show="showIosKefu" :type="matype" @close="closeIosKefu"></IosKefu>
			<AndrTaocan :show="showAndrTaocan" :taocanid="7" @close="closeAndrTaocan" @refsh="handlerefsh"></AndrTaocan>
		</view>
	</view>
</template>

<script>
	import IosKefu from '@/components/ioskefu.vue'
	import AndrTaocan from '@/components/andrtaocan.vue'
	export default {
		components: {
			IosKefu,
			AndrTaocan
		},
		data() {
			return {
				buymsg: '',
				showAndrTaocan: false,
				matype: '',
				showIosKefu: false,
				isIos: false,
				showWeekNotice: false,
				zhekouwx: '',
				zhekouye: '',
				userinfo: '',
				storeinfo: '',
				nodeTextwx: '',
				nodeTextye: ''
			};
		},
		onShow() {
			const info = wx.getSystemInfoSync()
			this.isIos = !(info.system.indexOf('Android') > -1)
			this.getStrorInfo2()
			this.userinfo = uni.getStorageSync('userInfo')
			this.getStoreInfo()
			this.getText()
		},
		methods: {
			handlerefsh() {
				this.getStrorInfo2()
			},
			handleShowAndrRenw() {
				this.showAndrTaocan = true
			},
			closeAndrTaocan() {
				this.showAndrTaocan = false
			},
			handleKefu() {
				this.showIosKefu = true
				this.matype = 'hyimg'
			},
			closeIosKefu() {
				this.showIosKefu = false
			},
			getStrorInfo2() {
				this.$req.post('/shanghu/userInfo', {
					uid: uni.getStorageSync('uid')
				}).then((res) => {
					let data = res.data.data
					this.buymsg = data.hytitle
					if (data.hyweak == 2) {
						this.showWeekNotice = true
					}
					if (data.hystrong === 2) {
						let flag = true
						if (uni.getStorageSync('wxtaoendtime')) {
							var ctime = new Date().getTime()
							if (ctime > uni.getStorageSync('wxtaoendtime')) {
								uni.removeStorageSync('wxtaoendtime')
							} else {
								flag = false
							}
						}
						if (this.isIos) {
							this.matype = 'hyimg'
							this.showIosKefu = flag
						} else {
							this.showAndrTaocan = flag
						}

						if (!uni.getStorageSync('wxtaoendtime')) {
							let endTime = new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 *
								60 *
								1000 - 1); // 当天23:59
							uni.setStorageSync('wxtaoendtime', endTime)
						}
					}

				})
			},
			getText() {
				this.$req.post('/shanghu/zhekousm', {}).then((res) => {
					this.nodeTextwx = res.data.data
				})
				this.$req.post('/shanghu/zhekouyesm', {}).then((res) => {
					this.nodeTextye = res.data.data
				})
			},
			handleSubmit() {
				if (!this.zhekouwx) {
					uni.showToast({
						icon: 'none',
						title: '请输入微信折扣值'
					})
					return
				}
				if (!this.zhekouye) {
					uni.showToast({
						icon: 'none',
						title: '请输入余额折扣值'
					})
					return
				}
				uni.showLoading({

				})
				this.$req.post('/shanghu/zhekouye', {
					shanghuid: this.userinfo.shanghuid,
					wxzhekou: Number(this.zhekouwx),
					zhekou: Number(this.zhekouye),
				}).then((res) => {
					uni.hideLoading()
					if (res.data.code === 0) {
						uni.showToast({
							title: '保存成功'
						})
					} else {
						uni.showToast({
							icon: 'none',
							title: res.data.msg
						})
					}
				})
			},
			getStoreInfo() {
				this.$req.post('/shanghu/shanghuInfo', {
					shanghuid: this.userinfo.shanghuid
				}).then(res => {
					let data = res.data.data
					this.zhekouwx = data.wxzhekou
					this.zhekouye = data.zhekou
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.weekNotice {
		padding: 15rpx 30rpx;
		position: fixed;
		bottom: 150rpx;
		left: 0;
		z-index: 100;
		width: 100%;
		background-color: #fdf6ec;
		color: #f9ae3d;
		font-size: 30rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.nodetext {
		width: 100%;
		padding-top: 30rpx;
		font-size: 28rpx;
		color: #999;
	}

	.info-box {
		padding: 20rpx 20rpx;
	}

	.img-list {
		padding-left: 32rpx;
		display: flex;

		justify-content: flex-start;

		.tit {
			font-size: 28rpx;
			margin-right: 30rpx;
		}
	}

	.add-img {
		width: 150rpx;
		height: 150rpx;
		border: #b1b3b9 dotted 1px;
		border-radius: 10rpx;
		margin-right: 20rpx;
	}

	.img-box {
		position: relative;
		width: 150rpx;
		height: 150rpx;
		margin-right: 20rpx;
	}

	.img-close {
		position: absolute;
		top: -10rpx;
		right: -10rpx;
		width: 32rpx;
		height: 32rpx;
		border-radius: 100rpx;
		background: rgba(0, 0, 0, 0.7);
	}

	.goods-img {
		width: 150rpx;
		height: 150rpx;
		border-radius: 10rpx;
	}

	.one-info {
		background: #f7f8fa;
		padding: 20rpx 32rpx;
		margin-top: 20rpx;
		border-radius: 10rpx;
		font-size: 28rpx;
		line-height: 70rpx;

		input {
			text-align: right;
			width: calc(100% - 200rpx);
			font-size: 28rpx;
		}
	}

	.bottom-box {
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 10;
		background: #fff;
		padding: 20rpx 20rpx;
		padding-bottom: 40rpx;
		box-shadow: 0 0 4px 2px #eeecef;
	}

	.one-btn {
		width: 100%;
		font-size: 28rpx;
		height: 90rpx;
		border-radius: 20rpx;
		color: #fff;
	}

	.one-spec {
		margin-top: 20rpx;
		border-top: #eeecef solid 1px;
	}

	.spec-box {
		text {
			width: 33%;
		}
	}

	.spec-info {
		width: 600rpx;
		padding: 20rpx 20rpx;
	}

	.cancel-btn {
		margin-top: 20rpx;
		width: 250rpx;
		height: 90rpx;
		border-radius: 10rpx;
		color: #606266;
		border: #eeecef solid 1px;
	}

	.confirm-btn {
		margin-top: 20rpx;
		width: 250rpx;
		height: 90rpx;
		border-radius: 10rpx;
		color: #fff;
	}

	.submit-btn {
		background: #eeecef;
		color: #606266;
	}
</style>